#include "layoutsettingsform.h"

#include <QLineEdit>
#include <QSpinBox>
#include <QComboBox>
#include <QStackedWidget>
#include <QPainter>
#include <QLabel>
#include <QPushButton>
#include <QHBoxLayout>
#include <QVBoxLayout>

LayoutSettingsForm::LayoutSettingsForm(QWidget *parent) :
    QWidget(parent)
{
    layoutUI();
    displayUI();
    connects();
}

LayoutSettingsForm::~LayoutSettingsForm()
{
}

void LayoutSettingsForm::slotLayout()
{
    m_pTitleLabel->setText(tr("Display Placement"));
    m_pStackedWdg->setCurrentIndex(1);
}

void LayoutSettingsForm::slotDisplay()
{
    m_pTitleLabel->setText(tr("Layout Manager"));
    m_pStackedWdg->setCurrentIndex(0);
}

void LayoutSettingsForm::displayUI()
{
    m_pDisplayButton=new QPushButton(tr("Layout Manager"));
    m_pDisplayButton->setObjectName("m_pDisplayButton");
    m_pDisplayButton->setFixedSize(100,60);
    //displayWdg
    SubWidget *displayWdg=new SubWidget;
    displayWdg->setObjectName("displayWdg");
    QLabel *displayLabel=new QLabel;
    displayLabel->setObjectName("displayLabel");
    displayLabel->setText(tr("Screen Display"));
    m_pDisplaySwitchButton=new QPushButton(tr("On"));
    m_pDisplaySwitchButton->setObjectName("m_pDisplaySwitchButton");

    QVBoxLayout *displayVLayout=new QVBoxLayout;
//    displayVLayout->setMargin(0);
    displayVLayout->addWidget(displayLabel);
    displayVLayout->addWidget(m_pDisplaySwitchButton);
    displayWdg->setLayout(displayVLayout);
    //replacementWdg
    SubWidget *replacementWdg=new SubWidget;
    replacementWdg->setObjectName("replacementWdg");
    QLabel *replaceLabel=new QLabel(tr("Display Replacement"));
    replaceLabel->setObjectName("replaceLabel");
    m_pDisplayLockButton=new QPushButton(tr("Lock"));
    m_pDisplayLockButton->setObjectName("m_pDisplayLockButton");
    m_pDisplayResetButton=new QPushButton(tr("Reset"));
    m_pDisplayResetButton->setObjectName("m_pDisplayResetButton");
    QHBoxLayout *displayLockHLayout=new QHBoxLayout;
    displayLockHLayout->addWidget(m_pDisplayLockButton);
    displayLockHLayout->addWidget(m_pDisplayResetButton);
    QVBoxLayout *replaceVLayout=new QVBoxLayout;
//    replaceVLayout->setMargin(0);
    replaceVLayout->addWidget(replaceLabel);
    replaceVLayout->addLayout(displayLockHLayout);

    replacementWdg->setLayout(replaceVLayout);
    //m_pDisplayManWdg
    QHBoxLayout *displayManHLayout=new QHBoxLayout;
        displayManHLayout->setMargin(0);
    //    displayManHLayout->setSpacing(0);
    displayManHLayout->addStretch(1);
    displayManHLayout->addWidget(m_pDisplayButton);
    displayManHLayout->addWidget(displayWdg);
    displayManHLayout->addWidget(replacementWdg);
    displayManHLayout->addStretch(1);

    m_pDisplayManWdg->setLayout(displayManHLayout);
}

void LayoutSettingsForm::connects()
{
    connect(m_pLayoutButton,SIGNAL(clicked(bool)),
            this,SLOT(slotLayout()));
    connect(m_pDisplayButton,SIGNAL(clicked()),
            this,SLOT(slotDisplay()));
}

void LayoutSettingsForm::layoutUI()
{
    setObjectName("LayoutSettingsForm");

    m_pTitleLabel=new QLabel;
    m_pTitleLabel->setObjectName("m_pTitleLabel");
    m_pTitleLabel->setFixedHeight(40);
    m_pTitleLabel->setAlignment(Qt::AlignCenter);
    m_pTitleLabel->setText(tr("Layout Manager"));

    m_pStackedWdg=new QStackedWidget;
    m_pStackedWdg->setObjectName("m_pStackedWdg");

    QVBoxLayout *layout=new QVBoxLayout;
    layout->setMargin(0);
//    layout->setSpacing(0);
    layout->addWidget(m_pTitleLabel,0,Qt::AlignVCenter);
    layout->addWidget(m_pStackedWdg);

    setLayout(layout);
    //layout wdg
    m_pLayoutManWdg=new QWidget;
    m_pLayoutManWdg->setObjectName("m_pLayoutManWdg");
    m_pStackedWdg->addWidget(m_pLayoutManWdg);
    m_pDisplayManWdg=new QWidget;
    m_pDisplayManWdg->setObjectName("m_pDisplayManWdg");
    m_pStackedWdg->addWidget(m_pDisplayManWdg);
    m_pStackedWdg->setCurrentIndex(0);

    QHBoxLayout *layoutManHLayout=new QHBoxLayout;
    m_pLayoutManWdg->setLayout(layoutManHLayout);

    m_pLayoutButton=new QPushButton(tr("Display Settings"));
    m_pLayoutButton->setObjectName("m_pLayoutButton");
    m_pLayoutButton->setFixedSize(120,60);
    //video
    SubWidget *videoWdg=new SubWidget;
    videoWdg->setObjectName("videoWdg");

    QLabel *videoWallLayoutManLabel=new QLabel(tr("Video Wall Layout Man"));
    videoWallLayoutManLabel->setObjectName("videoWallLayoutManLabel");
    QLabel *videoRowLabel=new QLabel(tr("Row"));
    videoRowLabel->setObjectName("videoRowLabel");
    QLabel *videoColumnLabel=new QLabel(tr("Column"));
    videoColumnLabel->setObjectName("videoColumnLabel");
    m_pRowSpinBox=new QSpinBox;
    m_pRowSpinBox->setObjectName("m_pRowSpinBox");
    m_pColumnSpinBox=new QSpinBox;
    m_pColumnSpinBox->setObjectName("m_pColumnSpinBox");
    m_pSetButton=new QPushButton(tr("Set"));
    m_pSetButton->setObjectName("m_pSetButton");

    QHBoxLayout *videoBottomHLayout=new QHBoxLayout;
    videoBottomHLayout->addWidget(videoRowLabel);
    videoBottomHLayout->addWidget(m_pRowSpinBox);
    videoBottomHLayout->addWidget(videoColumnLabel);
    videoBottomHLayout->addWidget(m_pColumnSpinBox);
    videoBottomHLayout->addWidget(m_pSetButton);

    QVBoxLayout *videoVLayout=new QVBoxLayout;
    videoVLayout->addWidget(videoWallLayoutManLabel);
    videoVLayout->addLayout(videoBottomHLayout);

    videoWdg->setLayout(videoVLayout);
    //plan
    SubWidget *planWdg=new SubWidget;
    planWdg->setObjectName("planWdg");

    QLabel *planLabel=new QLabel(tr("Plan Open/Save"));
    planLabel->setObjectName("planLabel");

    m_pPlanComboBox=new QComboBox;
    m_pPlanComboBox->setObjectName("m_pPlanComboBox");
    m_pPlanLineEdit=new QLineEdit;
    m_pPlanLineEdit->setObjectName("m_pPlanLineEdit");
    m_pPlanSaveButton=new QPushButton(tr("Save"));
    m_pPlanSaveButton->setObjectName("m_pPlanSaveButton");

    QHBoxLayout *planBottomHLayout=new QHBoxLayout;
    //    planBottomHLayout->setMargin(0);
    //    planBottomHLayout->setSpacing(0);
    planBottomHLayout->addWidget(m_pPlanComboBox);
    planBottomHLayout->addWidget(m_pPlanLineEdit);
    planBottomHLayout->addWidget(m_pPlanSaveButton);

    QVBoxLayout*planVLayout=new QVBoxLayout;
    //    planVLayout->setMargin(0);
    //    planVLayout->setSpacing(0);
    planVLayout->addWidget(planLabel);
    planVLayout->addLayout(planBottomHLayout);

    planWdg->setLayout(planVLayout);
    //action
    SubWidget *actionWdg=new SubWidget;
    actionWdg->setObjectName("actionWdg");

    QLabel *actionLabel=new QLabel(tr("Action"));
    actionLabel->setObjectName("actionLabel");
    m_pActionCleanButton=new QPushButton(tr("Clean"));
    m_pActionCleanButton->setObjectName("m_pActionCleanButton");
    m_pActionApplyButton=new QPushButton(tr("Apply"));
    m_pActionApplyButton->setObjectName("m_pActionApplyButton");

    QHBoxLayout *actionHLayout=new QHBoxLayout;
    actionHLayout->addWidget(m_pActionCleanButton);
    actionHLayout->addWidget(m_pActionApplyButton);

    QVBoxLayout*actionVLayout=new QVBoxLayout;
    actionVLayout->addWidget(actionLabel);
    actionVLayout->addLayout(actionHLayout);

    actionWdg->setLayout(actionVLayout);
    //control
    SubWidget *ctrWdg=new SubWidget;
    ctrWdg->setObjectName("ctrWdg");

    QLabel *ctrLabel=new QLabel(tr("Control"));
    ctrLabel->setObjectName("ctrLabel");

    m_pCtrComboBox=new QComboBox;
    m_pCtrComboBox->setObjectName("m_pCtrComboBox");
    m_pCtrLineEdit=new QLineEdit;
    m_pCtrLineEdit->setObjectName("m_pCtrLineEdit");
    m_pCtrApplyButton=new QPushButton(tr("Apply"));
    m_pCtrApplyButton->setObjectName("m_pCtrApplyButton");

    QHBoxLayout *ctrHLayout=new QHBoxLayout;
    ctrHLayout->addWidget(m_pCtrComboBox);
    ctrHLayout->addWidget(m_pCtrLineEdit);
    ctrHLayout->addWidget(m_pCtrApplyButton);

    QVBoxLayout *ctrVLayout=new QVBoxLayout;
    ctrVLayout->addWidget(ctrLabel);
    ctrVLayout->addLayout(ctrHLayout);

    ctrWdg->setLayout(ctrVLayout);
    //
    layoutManHLayout->setMargin(0);
//    layoutManHLayout->setSpacing(0);
    layoutManHLayout->addStretch(1);
    layoutManHLayout->addWidget(m_pLayoutButton);
    layoutManHLayout->addWidget(videoWdg);
    layoutManHLayout->addWidget(planWdg);
    layoutManHLayout->addWidget(actionWdg);
    layoutManHLayout->addWidget(ctrWdg);
        layoutManHLayout->addStretch(1);
}

SubWidget::SubWidget()
{

}

SubWidget::~SubWidget()
{

}

void SubWidget::paintEvent(QPaintEvent *event)
{
    Q_UNUSED(event);

    QStyleOption opt;
    opt.init(this);
    QPainter p(this);
    style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this);
}
